package com.ruoyi.ai.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ai.domain.AiConfig;
import com.ruoyi.ai.service.IAiConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * AI配置Controller
 *
 * @author ruoyi
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/khpx/aiconfig")
public class AiConfigController extends BaseController
{
    @Autowired
    private IAiConfigService aiConfigService;

    /**
     * 查询AI配置列表
     */
    @PreAuthorize("@ss.hasPermi('khpx:aiconfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiConfig aiConfig)
    {
        startPage();
        List<AiConfig> list = aiConfigService.selectAiConfigList(aiConfig);
        return getDataTable(list);
    }

    /**
     * 导出AI配置列表
     */
    @PreAuthorize("@ss.hasPermi('khpx:aiconfig:export')")
    @Log(title = "AI配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiConfig aiConfig)
    {
        List<AiConfig> list = aiConfigService.selectAiConfigList(aiConfig);
        ExcelUtil<AiConfig> util = new ExcelUtil<AiConfig>(AiConfig.class);
        util.exportExcel(response, list, "AI配置数据");
    }

    /**
     * 获取AI配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('khpx:aiconfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiConfigService.selectAiConfigById(id));
    }

    /**
     * 新增AI配置
     */
    @PreAuthorize("@ss.hasPermi('khpx:aiconfig:add')")
    @Log(title = "AI配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiConfig aiConfig)
    {
        return toAjax(aiConfigService.insertAiConfig(aiConfig));
    }

    /**
     * 修改AI配置
     */
    @PreAuthorize("@ss.hasPermi('khpx:aiconfig:edit')")
    @Log(title = "AI配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiConfig aiConfig)
    {
        return toAjax(aiConfigService.updateAiConfig(aiConfig));
    }

    /**
     * 删除AI配置
     */
    @PreAuthorize("@ss.hasPermi('khpx:aiconfig:remove')")
    @Log(title = "AI配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiConfigService.deleteAiConfigByIds(ids));
    }
}
